<?php

namespace app\service;

use app\model\CarModel;
use app\model\DriverModel;
use app\model\PartnerLogModel;
use app\model\PartnerUserModel;
use app\model\WarehouseModel;
use think\facade\Db;

class CarService
{
    public static function lists($param)
    {
        return CarModel::lists($param);
    }

    public static function line_data($param)
    {
        return CarModel::line_data($param);
    }

    public static function car_opdata($param)
    {
        $data = CarModel::car_opdata($param);
    }

    public static function info($param)
    {
        return CarModel::info($param);
    }

    public static function add($data, $logParam)
    {
        Db::startTrans();
        $data['no'] = "C" . GetRandInt(8);
        $data['add_time'] = getNowDateTime();
        $res = CarModel::add($data);
        $dataLog = [
            'partner_user_id' => $logParam['uid'],
            'log_type' => 2,
            'request_ip' => $logParam['ip'],
            'add_time' => getNowDateTime(),
            'log_desc' => '添加车辆',
            'status' => 1,
            'partner_id' => $data['partner_id']
        ];
        
        if ($res ) {
            Db::commit();
            return 10000;
        } else {
            // 回滚事务
            Db::rollback();
            return 10003;
        }
    }

    public static function edit($data, $logParam, $id)
    {
        Db::startTrans();
        $data['update_time'] = getNowDateTime();
        $res = CarModel::edit($data, $id);
        $dataLog = [
            'partner_user_id' => $logParam['uid'],
            'log_type' => 2,
            'request_ip' => $logParam['ip'],
            'add_time' => getNowDateTime(),
            'log_desc' => '修改车辆信息',
            'status' => 1,
            'partner_id' => $data['partner_id']
        ];
        
        if ($res ) {
            Db::commit();
            return 10000;
        } else {
            // 回滚事务
            Db::rollback();
            return 10003;
        }
    }

    public static function del($data, $logParam, $id)
    {
        Db::startTrans();
        $res = CarModel::del($id);
        $dataLog = [
            'partner_user_id' => $logParam['uid'],
            'log_type' => 2,
            'request_ip' => $logParam['ip'],
            'add_time' => getNowDateTime(),
            'log_desc' => '删除车辆信息',
            'status' => 1,
            'partner_id' => $data['partner_id']
        ];
        
        if ($res ) {
            Db::commit();
            return 10000;
        } else {
            // 回滚事务
            Db::rollback();
            return 10003;
        }
    }

    public static function concise_list($param)
    {
        return CarModel::conise_lists($param);
    }

    public static function carOper($param)
    {
        return CarModel::oper($param);
    }
}